package com.david.mydemo.ctl_redis.message.listen;

import com.alibaba.fastjson.JSON;
import com.david.mydemo.ctl_redis.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RedisUserMsgV1t1Handler implements MessageListener {

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String consumerChannel = RedisSerializer.string().deserialize(message.getChannel());
        if (!consumerChannel.equals("user-topic1")) {
            return;
        }
        byte[] body = message.getBody();
        String json = RedisSerializer.string().deserialize(body);
        UserDto userDto = JSON.parseObject(json, UserDto.class);
        log.info("handle1接收到：{}", userDto);
    }
}
